package za.ac.wits.was.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import za.ac.wits.was.enums.SessionAttribute;
import za.ac.wits.was.user.service.UserService;

/**
 *
 * @author Salman Noor : School of Electrical and Information Engineering
 * @Copyright: Wits University 2013 - All Rights Reserved
 * @email: salmannoor74415@gmail.com
 * @License: BSD License (http://www.linfo.org/bsdlicense.html)
 */
@Controller
@RequestMapping("/*")
public class HomeController {
    
        Logger L = Logger.getLogger(HomeController.class);
        
        @Autowired
        UserService userService;
        
            @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String home(ModelMap model,
            final HttpServletRequest httpServletRequest, final HttpSession session) {
                httpServletRequest.getSession().setAttribute(SessionAttribute.UserInformation.name(), userService.getUserFullName(httpServletRequest.getUserPrincipal().getName()));
                return "home";
            }
            
                @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(ModelMap model,
            final HttpServletRequest httpServletRequest) {

        return "login";
    }
                
                
    @RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
    public String loginerror(ModelMap model) {
        model.addAttribute("error", "true");
        return "login";
    }

    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public String logout(ModelMap model) {
        return "login";
    }
        
}
